package com.sushengren.easyword.converters;

import com.sushengren.easyword.enums.DataTypeEnum;
import com.sushengren.easyword.model.WriteData;

import java.util.ArrayList;
import java.util.List;

/**
 * 列表类型转换
 *
 * @author sushengren
 */
public class ListConverter implements Converter {

    @Override
    public WriteData convertToWriteData(String key, Object objList) {
        WriteData writeData = new WriteData(key);
        writeData.setKey(key);
        writeData.setValue(objList);
        writeData.setDataType(DataTypeEnum.LIST);
        List<List<WriteData>> listValue = new ArrayList<>();
        for (Object obj : ((Iterable) objList)) {
            listValue.add(BeanConverter.beanToWriteData(obj));
        }
        writeData.setListValue(listValue);
        return writeData;
    }

}
